package com.itheima.homework.bh1208;

import java.util.ArrayList;
import java.util.Objects;

/*【编号：1208】某公司发放年终礼品，但hr在统计的时候发现有很多同姓名同年龄的员工，所以决定对这一部分员工，
        发放【缘分大礼包】，其余员工发放【普通大礼包】，请用技术手段，完成礼品的分发。 现有4个员工信息：
        张三，23
        李四，24
        张三，23
        张三，28
                           运行结果：
Employee{name=张三,age=23}获得了缘分大礼包
Employee{name=李四,age=24}获得了普通大礼包
Employee{name=张三,age=23}获得了缘分大礼包
Employee{name=张三,age=28}获得了普通大礼包                */
public class demo8 {
    public static void main(String[] args) {
        ArrayList<Employee> list=new ArrayList<>();
        list.add(new Employee("张三",23));
        list.add(new Employee("李四",24));
        list.add(new Employee("张三",23));
        list.add(new Employee("张三",28));
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i).toString());
            for (int j = 0; j < list.size(); j++) {
                if (i!=j&&list.get(i).equals(list.get(j))){
                    System.out.println("获得了缘分大礼包");
                    break;
                }
                if (j==list.size()-1){
                    System.out.println("获得了普通大礼包");
                }
            }
        }
    }

}


class Employee{
    private String name;
    private int age;

    public Employee() {
    }

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return age==employee.age&& Objects.equals(name,employee.name);

    }
public String toString(){
        return "Employee{name="+name+",age="+age+"}";
}

}